<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="../js/jquery.min.js"></script>
    <title>注册新账号</title>

    <style>
        div{
            width:400px;
            height:200px;
            position: absolute;
            top:50%;
            left:50%;
            margin-top: -100px;
            margin-left:-200px;
            font: 20px;
        }
        button{
            width:130px!important;
            height:40px!important;
        }
     </style>

     <script>
       $(function(){
        	 $("#getCodeBtn").bind("click",function(){
        	      $.ajax({
                     type: 'GET',
                     url: 'http://www.test.com/api/code/create/' + $('#email').val(),
                     success: function(data){
                            if("true"==data + "") {
                                alert("验证码已发送到邮箱，请查收");
                            }else{
                             	 alert("验证码获取失败");
                            }
                     	},
                     	error: function(){
                            	alert("验证码获取失败")
                    	 }
            	     })
        	   })

               $("#registerBtn").bind("click",function(){
                  $.ajax({
                     type: 'GET',
                     url: 'http://www.test.com/api/user/register/' + $('#email').val() + "/" + $('#password').val() + "/" + $('#code').val(),
                     success: function(data){
                            if("0" == data + "") {
                                location.href = "./welcome.html";
                            }else if("1" == data + ""){
                                alert("验证码错误");
                            }else if("2" == data + ""){
                                alert("验证码超时");
                            }else if("-1" == data + ""){
                                alert("该邮箱已经注册过账号");
                            }else {
                                alert(data);
                            }
                        },
                        error: function(){
                                alert("注册失败")
                         }
                     })
               })

            })
     </script>
</head>
<body>

    <div>
            <table>
                <tr>
                    <td>邮箱：</td>
                    <td><input type="text" id="email"></td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td>
                        <input type="password" id="password"> 
		    </td>
                </tr>
		<tr>
                    <td>确认密码：</td>
                    <td>
                        <input type="password" id="ConfirmPassword">
                    </td>
                </tr>
		<tr>
                    <td>验证码：</td>
                    <td>
                        <input type="text" id="code">&nbsp;&nbsp;<a href="#" id="getCodeBtn">获取验证码</a>
                    </td>
                </tr>



		<tr>
		    <td></td>
		    <td>
                        <input type="button" id="registerBtn" value="注册"/>
		    </td>
		</tr>
            </table>
	 </div>
</body>
</html>
